package top.fkxuexi.blogapi.modules.auth.controller;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.fkxuexi.blogapi.core.utils.common.Code;
import top.fkxuexi.blogapi.core.utils.common.Result;
import top.fkxuexi.blogapi.modules.auth.entity.SysMenu;
import top.fkxuexi.blogapi.modules.auth.entity.SysRole;
import top.fkxuexi.blogapi.modules.auth.entity.SysRoleMenu;
import top.fkxuexi.blogapi.modules.auth.service.SysRoleMenuService;
import top.fkxuexi.blogapi.modules.auth.service.SysRoleService;

import java.util.List;

/**
 * @Author blog.fkxuexi.top
 * @Gitee: https://gitee.com/smartwork/
 * @Descri: 角色资源表
 */
@Controller
@RequestMapping(value = "/admin/role/menu")
public class SysRoleMenuController {


    @Autowired
    private SysRoleMenuService roleMenuService;
    @Autowired
    private SysRoleService roleService;

    @RequestMapping(value = "/list")
    @ResponseBody
    public Result getRoleMenu(){
        Integer principal = (Integer) SecurityUtils.getSubject().getPrincipal();
        // 需要注意的是，这个地方用户可能是拥有多个权限的
        List<SysRole> roleList = roleService.getRoleListByUserId(principal);
        // 获取所有的菜单
        List<SysMenu> roleMenuList = roleMenuService.getRoleMenu(roleList);
        return new Result(Code.SUCCESS,true,roleMenuList);
    }

}